<?php 
namespace app\model;

use think\model;
use think\facade\Db;

class OrderModel extends Model 
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'order';
    // 设置当前模型的数据库连接
    //protected $connection = 'db_config';
    //protected $pk = 'id';

    protected $payment = array(
        'wx'=>'微信',
        'alipay'=>'支付宝',
        'bank'=>'银行卡',
        'cash'=>'现金'
    );

    // 模型初始化
    protected static function init()
    {
        //TODO:初始化内容

    }

    //流水号产生
    //220101-1
    static function getFlowNo(){
        $today = date("ymd",time());
        $order = Db::query("select order_no from `order` order by id desc limit 1");

        if(!count($order)){
            $order_no=$today."-1"; //没有订单，第一号
        }else{
            $arr = explode("-",$order[0]['order_no']);
            if($arr[0]!=$today || empty($arr[1])){
                $order_no=$today."-1";  //今天第一号
            }else{
                $order_no = $arr[0]."-".($arr[1]+1);
            }
        }
        return $order_no;
    }
    


}

